async function Login(username, password) {
    try {
        pxmu.loading('请稍等....');
        let res = await axios({
            url: '/login',
            method: 'POST',
            data: {
                username: username,
                password: password
            }
        })
        console.log(res.data);
        if (res.data.code === 10000) {
            localStorage.setItem('username', `${res.data.data.username}`)
            localStorage.setItem('token', `${res.data.data.token}`)
            pxmu.fail('登入成功哦,将为您跳转登入页面哦')
            setTimeout(() => {
                // 当结果返回的时候，关闭这个提示
                pxmu.closeload(100)
                location.href = 'index.html'
            }, 3000)
        } else {
            pxmu.fail('请检查账号和密码是否正确')
        }
    } catch(err) {
        pxmu.fail(err.response.data.message || '登录失败，请检查网络请求')
    }

}
document.querySelector('#btn-login').addEventListener('click', function (e) {
    // 阻止默认行为
    e.preventDefault()
    const form = document.querySelector('.login-form')
    const data = serialize(form, { hash: true, empty: true })
    const username = data.username
    const password = data.password
    // console.log(username,password);
    if (panduan(username,password)) {
        Login(username, password)
    } else {
        pxmu.fail('用户名和密码不合规')
    }
})
document.querySelector('.input-group-append').addEventListener('click', function (e) {
    // console.log(e.target.tagName);
    if (e.target.tagName === 'I') {
        if (document.querySelector('#input-password').type === 'password') {
            document.querySelector('#input-password').type = 'text'
            e.target.classList.remove('bi-eye-fill')
            e.target.classList.add('bi-eye-slash')
        } else {
            document.querySelector('#input-password').type = 'password'
            e.target.classList.remove('bi-eye-slash')
            e.target.classList.add('bi-eye-fill')
        }
    }
})